// Author: Domien Nowicki

#include "HumanPlayerWidget.h"
#include "MapWidget.h"
#include "Game.h"
#include "Properties.h"


HumanPlayerWidget::HumanPlayerWidget(QWidget *parent, Game* game, Map* map, const Properties& properties) : Player(game, map, properties), PaintPaletteWidget(parent, properties)
{
	MapWidget *mapWidget = (MapWidget*)map;

	// This is a human player
	SetHuman(true);

	// Connect color changed and cursor changed signals
	QObject::connect(this, SIGNAL(colorChanged(Color)), this, SLOT(slotSetColor(Color)));
	QObject::connect(this, SIGNAL(cursorChanged(const QCursor&)), this, SLOT(slotSetCursor(const QCursor&)));

	// Connect signal when user clicked on a province
	QObject::connect(mapWidget, SIGNAL(clickedProvince(Map*, Land*, Province*)), this, SLOT(slotClickedProvince(Map*, Land*, Province*)));

	// Set default palette color
	Color eraseColor;
	SetPaletteColor(eraseColor);
}

HumanPlayerWidget::~HumanPlayerWidget()
{
}

void HumanPlayerWidget::slotClickedProvince(Map *nmap, Land* land, Province *province)
{
	// When user clicked a province, do the move it wanted to do
	Move move(nmap, land->GetName(), province->GetName(), color);

	DoMove(move);
}

void HumanPlayerWidget::slotSetColor(Color newColor)
{
	// Selected a new color, update it
	SetColor(newColor);
}

void HumanPlayerWidget::slotSetCursor(const QCursor& cursor)
{
	MapWidget *mapWidget = (MapWidget*)map;

	// Selected a new cursor, update it
	mapWidget->SetCursor(cursor);
}






